package com.xinzhitong.www.controller;

import com.xinzhitong.www.exception.news.NewsIsNullException;
import com.xinzhitong.www.service.NewsService;
import com.xinzhitong.www.utils.Message;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 新闻控制器
 *
 * @author 魏骆淳
 */
@CrossOrigin
@RestController
@RequestMapping("news")
public class NewsController {

    @Resource
    private NewsService newsService;

    /**
     * 获取新闻链接
     *
     * @param newsId 新闻id
     * @return 新闻链接
     */
    @RequestMapping(value = "getNewsUrl", method = RequestMethod.GET)
    public Message newsUrl(
            @Param("newsId") Integer newsId
    ) {
        try {
            return Message.createSuc(newsService.selectNewsUrl(newsId));
        } catch (NewsIsNullException e) {
            e.printStackTrace();
        }
        return Message.createErr("新闻链接为空");
    }

}
